package com.example.demo.auto.controller;

import com.beiding.businessplatform.data.Vm;
import com.beiding.businessplatform.request.R;
import com.beiding.businessplatform.request.Requester;
import com.example.demo.auto.model.A;
import com.example.demo.manual.service.AService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/b")
public class BController {

    @Autowired
    private AService service;

    /*
        所有的操作都采用请求体传参且post请求

        请求将被封装为请求器

        优点:
            简单且风格统一
     */
    @PostMapping("/change-name")
    R changeName(@RequestBody(required = true) String body) {
        Requester<A> requester = new Requester<>(body, A.class);
        service.changeName(requester);
        return requester.getR();
    }


    public static void main(String[] args) {

        Requester<?> requester = new Requester<>("{a:{name:\"丁常磊\"}}");

        A a = requester.getVm("a", A.class);

        System.out.println(a.getName());

    }


}
